package com.sam;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.mysql.jdbc.Driver;

public class Member {
	String userId=null;
	String nickName=null;
	String passWord=null;
	String eMail=null;
	String loginMsg=null;
	private boolean isLogin;
	
	public boolean loginIn() {
		isLogin = false;
		Connection conn = null;
		PreparedStatement pstmt = null;
		
		try {
			DriverManager.registerDriver(new Driver());
			conn = DriverManager.getConnection("jdbc:mysql://j.snpy.org/j102", "jstu", "abc123");
			String sql = "select * from users where id=? and password=?";
			pstmt = conn.prepareStatement(sql);
			pstmt.setString(1, userId);
			pstmt.setString(2, passWord);
			ResultSet rs = pstmt.executeQuery();
			if (rs.next()){
				isLogin = true;
				nickName = rs.getString("nickName");
			}else{
				isLogin = false;
				loginMsg = "登入失敗 !!";
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return isLogin;
	}	
	
	public Member() {
		
	}

	protected Member(String userId, String nickName, String passWord,
			String eMail) {
		super();
		this.userId = userId;
		this.nickName = nickName;
		this.passWord = passWord;
		this.eMail = eMail;
	}
	
	protected Member(String userId, String passWord) {
		super();
		this.userId = userId;
		this.passWord = passWord;
	}

	public String getUserId() {
		return userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}

	public String getNickName() {
		return nickName;
	}

	public void setNickName(String nickName) {
		this.nickName = nickName;
	}

	public String getPassWord() {
		return passWord;
	}

	public void setPassWord(String passWord) {
		this.passWord = passWord;
	}

	public String geteMail() {
		return eMail;
	}

	public void seteMail(String eMail) {
		this.eMail = eMail;
	}

	public String getLoginMsg() {
		return loginMsg;
	}

	public void setLoginMsg(String loginMsg) {
		this.loginMsg = loginMsg;
	}

	public boolean isLogin() {
		return isLogin;
	}

	public void setLogin(boolean isLogin) {
		this.isLogin = isLogin;
	}
	
	
}
